require "Battle/Entity/Entity"

EditorEntity = Entity:new();
EditorEntity.__index = EditorEntity;

function EditorEntity:new(roleInfo)
    local object =  Entity:new(roleInfo);
    setmetatable(object, EditorEntity);
    return object;
end

function EditorEntity:ShakeCamera(skillData,effType,targetObj)
    local cameraDo;
    local cameraTarget;
    if effType == 1 then
        cameraDo = Entity:GetTableValue(skillData,"f_CameraPushin");
        --cameraTarget = Entity:GetTableValue(skillData,"cameraTarget");
    elseif(effType == 3) then
        cameraDo = Entity:GetTableValue(skillData,"f_CameraShock");
    else
    end
    if cameraDo == nil then
        return;
    end
    
    if effType == 3 then --震动
        local shakelist = string.split(cameraDo,"|");
        for i=1,#shakelist do
            if string.len(shakelist[i]) > 3 then
                local strArr = string.split(shakelist[i],",");
                local shakeTime = tonumber(strArr[1]);
                local delayTime = tonumber(strArr[2]);
                local shakeType = tonumber(strArr[3]);
                local shakeStrength = tonumber(strArr[4]);
                local shakePower = tonumber(strArr[5]);

                if(shakeType == nil or shakeType > 3) then
                    shakeType = 0;
                end
                if shakeStrength == nil then
                    shakeStrength = 0.5;
                end
                if shakePower == nil then
                    shakePower = 1;
                end
                SkillRoleMgr.ShakeCamera(shakeTime,delayTime,shakeType,shakeStrength,shakePower);
            end
        end
    elseif effType == 1 then --推屏

        if(string.len(cameraDo) < 3 ) then
            return;
        end
        local strArr = string.split(cameraDo,",");
        local shakeTime = tonumber(strArr[2]);
        local delayTime = tonumber(strArr[3]);
        local backTime = tonumber(strArr[4]);
        local moveDist = tonumber(strArr[5]);

        if backTime == nil then
            backTime = 400;
        end
        if moveDist == nil then
            moveDist = 4;
        end
        SkillRoleMgr.ZoomCamera(self:getTargetPos(tonumber(cameraTarget),targetObj),shakeTime,delayTime,backTime,moveDist);
    end
end

function EditorEntity:playHurtAndEffCoroutine(skillId, skillLevel, skillData, targetRole)
    local singtime = Entity:GetTableValue(skillData,"f_SingingTime");
    if singtime ~= nil and singtime > 0 then
        coroutine.wait(tonumber(singtime)/1000);
    end

    local guideTime = Entity:GetTableValue(skillData,"f_GuideTime");
    -- Util.WaitForSeconds(function ()
    --     --受击特效和动作
    --     local playtimes = decodeJsonStrToTabel(Entity:GetTableValue(skillData,"f_DelayTime"));
    --     for i=1,#playtimes do
    --         coroutine.start(targetRole.playHurtCoroutine,targetRole,tonumber(playtimes[i])/1000,skillData,skillLevel);
    --     end
    -- end, tonumber(guideTime/1000));

    utimer.delayCall(function()   
        --受击特效和动作
        local playtimes = decodeJsonStrToTabel(Entity:GetTableValue(skillData,"f_DelayTime"))
        for i=1,#playtimes do
            coroutine.start(targetRole.playHurtCoroutine,targetRole,tonumber(playtimes[i])/1000,skillData,skillLevel)
        end
    end, tonumber(guideTime) )
end